package com.hxd.otc.module.my.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseBean;
import com.hxd.otc.common.UserHelper;
import com.hxd.otc.common.enums.YsApplyStatusEnum;
import com.hxd.otc.module.my.bean.AppInfoBean;
import com.hxd.otc.module.my.bean.YsPreBean;
import com.hxd.otc.module.my.contract.MyContract;
import com.hxd.otc.module.my.model.BondModel;
import com.hxd.otc.module.my.model.UserModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;
import com.hxd.otc.utils.ResourceUtil;

/**
 * 作  者 :  卫广玉
 * 时  间 :  2018/6/6 16:05
 * 描  述 :  ${我的Presenter}
 */
public class MyPresenter extends BasePresenter<MyContract.View> implements MyContract.Presenter{

    private final UserModel mUserModel;
    private final BondModel mBondModel;
    private YsPreBean mYsPreBean;

    public MyPresenter(MyContract.View view) {
        super(view);
        mUserModel = UserModel.getInstance();
        mBondModel = BondModel.getInstance();
    }

    @Override
    public void getUnreadMessageNums() {
//        mNoticeModel.getNoticeUnReadNum(new BaseObserver<Integer>() {
//            @Override
//            public void onNext(@NonNull String msg, @NonNull Integer num) {
//                mView.notifyUnReadNum(num);
//            }
//
//            @Override
//            public void onError(int errType, @NonNull String errMessage) {
//
//            }
//        },mView.<BaseBean<Integer>>bindAutoDispose());
    }

    @Override
    public void getUpdateVersionInfo() {
        mUserModel.getUpdateAppInfo(new BaseObserver<AppInfoBean>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull AppInfoBean appInfoBean) {
                mView.getUpdateVersionInfoSuccess(appInfoBean);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
            }
        }, mView.<BaseBean<AppInfoBean>>bindAutoDispose());
    }


    @Override
    public void requestYsApplyPreInfo() {
        mBondModel.requestYsApplyPreInfo(new BaseObserver<YsPreBean>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull YsPreBean ysPreBean) {
                mYsPreBean = ysPreBean;
                UserHelper.setTag(ysPreBean.getTag());
                UserHelper.updateRoleType(ysPreBean.getRole());
                if (UserHelper.isSilver()) return;
                mView.updateYsApplyStatus(YsApplyStatusEnum.getInstance(ysPreBean.getStatus()));
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.getApplyBondInfoFail(errMessage);
            }
        }, mView.<BaseBean<YsPreBean>>bindAutoDispose());
    }

    @Override
    public YsPreBean getYsPreBean() {
        if (mYsPreBean == null) {
            mView.showToast(ResourceUtil.getString(R.string.we_are_checking_the_status_of_advertiser_authentication_again_for_you));
            requestYsApplyPreInfo();
            return null;
        }
        return mYsPreBean;
    }
}